import requests
from django.conf import settings


def request_unlock(token):
    url = settings.LOCKS_UNLOCK_URL.replace("{lock_token}", token)
    response = requests.post(url)
    return parse_requests_response(response.status_code, response)


def parse_requests_response(code, response):
    response_data = response.json() if response.text != "" else {}
    return {
        "code": code,
        "ok": int(str(code)[0]) in [2, 3],
        "message": response_data["message"] if "message" in response_data else ""
    }
